<?php
class ArticleController extends BaseController {
    private $article_model;

    public function add() {
        return array(
            'tpl' => 'article/add',
        );
    }

    public function addSubmit($book_sid) {
        $article_model = new ArticleModel();
        $input = $this->getInput('post');
        $input['book_sid'] = $book_sid;
        $article_model->add($input);
        return array(
            'tpl' => 'article/add_submit',
        );
    }

    public function get($book_sid) {
        $article_model = new ArticleModel();
        $input = $this->getInput('get');
        $input['book_sid'] = $book_sid;
        $r = $article_model->getArticles($book_sid);
        $book_model = new BookModel();
        $book = $book_model->getBySid($book_sid);
        return array(
            'tpl' => 'article/read',
            'data' => array(
                'book' => $book,
                'articles' => $r,
            ),
        );
    }

    public function edit($book_sid, $article_number) {
        $m = new ArticleModel();
        $r = $m->getByNumber($book_sid, $article_number);
        return array(
            'tpl' => 'article/edit',
            'data' => $r,
        );
    }

    public function editSubmit($book_sid, $article_number) {
        $m = new ArticleModel();
        $input = $this->getInput('post');
        $m->update($book_sid, $article_number, $input);
        return array(
            'tpl' => 'article/edit_submit',
        );
    }
}
?>
